package com.app.business.service.newTextForCs;


import com.app.business.model.newTextForCs.TextHouseHoldAndArea;
import com.app.system.jpa.JpaBaseDao;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

/**
 * 超出房源面积单价配置
 * Created by DDZ on 2020/1/25.
 */
@SuppressWarnings(value = "ALL")
@Service
@Transactional
public class TextHouseHoldAndAreaService extends JpaBaseDao<TextHouseHoldAndArea, Integer> {

    /**
     * 删除某参数配置下所有的面积户型配置数据
     *
     * @param zsProjectId
     */
    public synchronized void deleteTextHouseHoldAndAreaByTextParameterId(Integer textParameterId) {
        String sql = "delete from text_house_hold_and_area where text_parameter_id = :textParameterId";
        this.entityManager.createNativeQuery(sql).setParameter("textParameterId", textParameterId).executeUpdate();
    }

    /**
     * 通过参数配置得到下面所有的面积户型
     *
     * @return
     */
    public List<TextHouseHoldAndArea> getTextHouseHoldAndAreaListByTextParameterId(Integer textParameterId) {
        //查询语句
        StringBuffer hql = new StringBuffer("from TextHouseHoldAndArea thhaa where thhaa.textParameter.id =:textParameterId order by thhaa.sortNum");
        Map map = Maps.newHashMap();
        map.put("textParameterId", textParameterId);
        return this.findHql(hql.toString(), map);
    }

}
